package org.geektimes.reactive.streams;

import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;

import java.util.logging.Logger;

/**
 * @FileName: SubscriptionAdapter
 * @Description: TODO
 * @Author: MaWenHao
 * @Created: 2021/3/31 - 11:01
 * @Version: V1.0
 * @Company: 东方微银科技（北京）有限公司
 */
public class SubscriptionAdapter implements Subscription {

    private Logger log = Logger.getLogger(this.getClass().getName());

    private final DecoratingSubscriber<?> subscriber;

    public SubscriptionAdapter(Subscriber subscriber) {
        this.subscriber = new DecoratingSubscriber<>(subscriber);
    }

    @Override
    public void request(long l) {
        if (l < 1) {
            throw new IllegalArgumentException("The number of elements to requests must be more than zero!");
        }
        this.subscriber.setMaxRequest(l);
    }

    @Override
    public void cancel() {
        subscriber.cancel();
    }

    public Subscriber getSubscriber() {
        return subscriber;
    }

    public Subscriber getSourceSubscriber() {
        return subscriber.getSource();
    }
}
